package org.example;

import net.sf.cglib.proxy.Enhancer;

import java.lang.reflect.Proxy;

/**
 * ClassName: Test
 * Package: org.example
 * Description:
 *
 * @Author wanghao
 * @Create 2024-07-08 8:58
 * @Version 1.0
 */
public class Test {

    public static void main(String[] args) {
        // 1.创建目标对象
        WuDa target = new WuDa();
        // 2.创建interceptor对象
        WuDaInterceptor interceptor = new WuDaInterceptor();
        /*
        // 3.创建Enhancer对象,它以目标类和interceptor作为原料，生产出代理对象
        Enhancer enhancer = new Enhancer();
        // 此处为什么是Superclass?
        // 因为CGLIB产生的代理对象是目标类的子类
        enhancer.setSuperclass(target.getClass());
        enhancer.setCallback(interceptor);
        WuDa proxy = (WuDa) enhancer.create();
         */

        WuDa proxy = (WuDa) interceptor.createProxy(target);
        proxy.saleShaoBing();
        proxy.saleJuice();
    }
}
